<template>
  <div class="card-container">
    <!-- <div class="list">
      <div class="item" v-for="(item, index) in tableData" :key="index"> -->
        <draggable 
          :list="tableData"
          animation="250"
          item-key="id"
          drag-class="drag-class"
          :force-fallback="true"
          group="dragArea"
          filter=".unmover"
          handle=".move-btn"
          class="list"
          @sort="handleSort"
          @add="handleContentAdd"
        >
          <template #item="{element}">
            <div class="item">
              <div class="ruifox-card-top">
                <div class="card-top-bg unmover" :class="{'ding-yes': element.top === 1,'ding-no': element.top === 0}" @click="toggleTop(element)">
                  <span>顶</span>
                </div>
              </div>
              <div class="detail">
                  <a class="thumb">
                    <img :src="element.thumb">
                  </a>
                  <h2><a>{{element.title.replace(/<[^>]+>/g,"")}}</a></h2>
                  <div class="info">
                    <div class="depart-info">
                      <u>科室：</u>
                        <a :title="element.depart.replace(/<[^>]+>/g, '')" >{{element.depart.replace(/<[^>]+>/g, '')}}</a>
                    </div>
                    <div class="zhicheng"><u>职称：</u>{{element.doc_position}}</div>
                  </div>
              </div>
              <div class="btns">
                <div class="left-btn">
                <!-- <div v-if="header.name === 'status'"> -->
                  <el-tag v-if="element.type === 1" type="success">已发布</el-tag>
                  <el-tag v-if="element.type === 2" type="warning">即将发布</el-tag>
                  <el-tag v-if="element.type === 3" type="info">即将撤稿</el-tag>
                <!-- </div> -->
                  <span
                    :title="element.is_locked === 1 ? '解锁' : '上锁'"
                    :class="{'is-locked': element.is_locked === 1}"
                    class="lock-icon"
                    @mouseenter="element.invertLock = element.is_locked  === 1 ? 0 : 1"
                    @mouseleave="element.invertLock = element.is_locked  === 1 ? 1 : 0"
                    @click="toggleLock(element)"
                  >
                    <i class="iconfont" v-show="element.is_locked === 1 || (element.id === showCardOptions.id && showCardOptions.show)" v-html="element.invertLock === 1 || element.is_locked === 1 && element.invertLock === undefined ? '&#xe6e0;' : '&#xe6df;'"></i>
                  </span>
                </div>

                <div class="right-btn">
                  <el-button class="option-btn" text size="small" :class="{'is-disabled': element.is_locked === 1 || element.can_edit === 0}" :disabled="element.is_locked === 1 || element.can_edit === 0" @click="handleEdit(element)">
                    <i class="iconfont">&#xe6e6;</i>
                    编辑
                  </el-button>
                  <el-dropdown>
                    <el-button class="more-btn" text size="small">
                      <i class="iconfont">&#xe6dc;</i>
                    </el-button>
                    <template #dropdown>
                      <el-dropdown-menu @mouseenter="showOptions(element.id)">
                        <el-dropdown-item type="primary" plain size="small" v-if="element.is_locked === 1 && element.enable_unlock === 1" @click="handleUnlock(element)">
                          <i class="iconfont">&#xe6df;</i>
                          解锁
                        </el-dropdown-item>
                        <el-dropdown-item type="primary" plain size="small" v-if="element.is_locked === 0 && element.enable_lock === 1" @click="handleLock(element)">
                          <i class="iconfont">&#xe6e0;</i>
                          上锁
                        </el-dropdown-item>
                        <el-dropdown-item type="primary" plain size="small" v-if="element.is_collect === 0" @click="handleCollect(element)">
                          <i class="iconfont">&#xe6f4;</i>
                          收藏
                        </el-dropdown-item>
                        <el-dropdown-item type="primary" plain size="small" v-if="element.is_collect === 1" @click="handleCancelCollect(element)">
                          <i class="iconfont">&#xe6f3;</i>
                          取消收藏
                        </el-dropdown-item>
                        <el-dropdown-item v-if="element.top === 0" @click="handleTop(element)"><i class="iconfont">&#xe6f2;</i>置顶</el-dropdown-item>
                        <el-dropdown-item v-if="element.top === 1" @click="handleCancelTop(element)"><i class="iconfont">&#xe6f1;</i>取消置顶</el-dropdown-item>
                        <el-dropdown-item @click="handlePreview(element)"><i class="iconfont">&#xe6ee;</i>预览</el-dropdown-item>
                        <el-dropdown-item @click="handleViewFront(element)"><i class="iconfont">&#xe6ef;</i>前台浏览</el-dropdown-item>
                        <el-dropdown-item @click="handleHisLog(element)"><i class="iconfont">&#xe6e9;</i>操作日志</el-dropdown-item>
                        <el-dropdown-item @click="handleAuditLog(element)"><i class="iconfont">&#xe6ea;</i>审核日志</el-dropdown-item>
                        <el-dropdown-item @click="handleArchive(element)"><i class="iconfont">&#xe709;</i>手动归档</el-dropdown-item>
                        <el-dropdown-item @click="handleMove(element)"><i class="iconfont">&#xe6eb;</i>移动</el-dropdown-item>
                      </el-dropdown-menu>
                    </template>
                  </el-dropdown>
                </div>
              </div>
            </div>
          </template>
        </draggable>
      <!-- </div>
    </div> -->
  </div>
</template>
<script setup>
import { computed, reactive } from 'vue'
import draggable from "vuedraggable";
const props = defineProps({
  tableData:{
    type: Array,
    default: () => {
      return []
    }
  }
})
const tableData = computed(()=>{return props.tableData})
console.log('tableData',tableData.value);
const showCardOptions = reactive({
  id: 0,
  show: false,
})
const emits = defineEmits([
  'handleEdit',
  'handleSort',
  'toggleTop',
  'toggleLock',
  'showOptions',
  'handleUnlock',
  'handleContentAdd',
  'handleLock',
  'handleCollect',
  'handleCancelCollect',
  'handleTop',
  'handleCancelTop',
  'handlePreview',
  'handleViewFront',
  'handleHisLog',
  'handleAuditLog',
  'handleArchive',
  'handleMove',
])
const handleEdit = (val) => {
  emits('handleEdit', val)
}
const handleSort = (val) => {
  emits('handleSort', val)
}
const toggleTop = (val) => {
  emits('toggleTop', val)
}
const toggleLock = (val) => {
  emits('toggleLock', val)
}
const showOptions = (val) => {
  emits('showOptions', val)
}
const handleUnlock = (val) => {
  emits('handleUnlock', val)
}
const handleContentAdd = (val) => {
  emits('handleContentAdd', val)
}
const handleLock = (val) => {
  emits('handleLock', val)
}
const handleCollect = (val) => {
  emits('handleCollect', val)
}
const handleCancelCollect = (val) => {
  emits('handleCancelCollect', val)
}
const handleTop = (val) => {
  emits('handleTop', val)
}
const handleCancelTop = (val) => {
  emits('handleCancelTop', val)
}
const handlePreview = (val) => {
  emits('handlePreview', val)
}
const handleViewFront = (val) => {
  emits('handleViewFront', val)
}
const handleHisLog = (val) => {
  emits('handleHisLog', val)
}
const handleAuditLog = (val) => {
  emits('handleAuditLog', val)
}
const handleArchive = (val) => {
  emits('handleArchive', val)
}
const handleMove = (val) => {
  emits('handleMove', val)
}
</script>
<style scoped lang='scss'>
.card-container{
  .list{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    .item{
      width: 276px;
      height: 210px;
      box-sizing: border-box;
      border: 1px solid #e5e5e5;
      padding: 19px;
      margin-right: 32px;
      margin-bottom: 30px;
      position: relative;
      transition: all .3s;
      transition: border-color .3s,box-shadow .3s;
      position: relative;
      &:hover{
        border-color: #1D9D9A;
        box-shadow: 0px 0.5rem 1.5rem rgba(29, 157, 154, 0.2);
      }
      .ruifox-card-top{
        position: absolute;
        left: 0;top: 0;
        width: 50px; height: 50px;
        overflow: hidden;
        .card-top-bg{
          position: absolute;
          height: 100%;width: 100%;
          transform: rotate(45deg);
          background-color: red;
          top: -25px;left: -25px;
          cursor: pointer;
        }
        .ding-yes:hover{
          background-color: #f78a7e;
        }
        .ding-yes{
          background-color: #FF5240;
        }
        .ding-no{
          background-color: #D7D7D7;
          visibility: hidden;
        }
        .ding-no:hover{
          background-color: #817f7f;
        }
        span{
          cursor: pointer;
          position: absolute;
          display: block;
          color: #FFFFFF;
          font-size: 12px;
          right: 6px;
          transform: rotate(-45deg);
          top: 18px;
        }
      }
      .detail{
        position: relative;
        height: 122px;
        padding-left: 105px;
        padding-bottom: 20px;
        margin-bottom: 10px;
        border-bottom: 1px solid #e5e5e5;
        .thumb{
          position: absolute;
          top: 0;
          left: 0;
          width: 85px;
          height: 116px;
          overflow: hidden;
          border-radius: 5px;
          img{
            width: 100%;
            height: 100%;
          }
        }
        h2{
          font-size: 18px;
        }
        .info{
          line-height: 27px;
          margin-top: 10px;
          .depart-info{
            font-size: 14px;
            color: #999;
            text-decoration: none;
            u{
              font-size: 14px;
              color: #999;
              text-decoration: none;
            }
            a{
              font-size: 14px;
              color: #444;
              outline: none;
              transition: all .3s;
            }
          }
          .zhicheng{
            font-size: 14px;
            color: #444;
            u{
              color: #999;
              text-decoration: none;
            }
          }
          div{
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
      .btns{
        display: flex;
        justify-content: space-between;
        align-items: center;
        .right-btn{
          .option-btn{
            i{
              color: $mainColor;
              margin-right: 2px;
            }
            &.is-disabled{
              i{
                color: #aaa;
              }
            }
          }
          .more-btn{
            i{
              font-size: 24px;
            }
          }
        }
      }
      p{
        color: #666;
        line-height: 22px;
        max-height: 66px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        word-wrap: break-word;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        display: -webkit-box !important;
      }
      .code-box{
        position: absolute;
        top: 4px;
        right: 4px;
        width: 32px;
        height: 32px;
        overflow: visible;
        cursor: pointer;
      }
    }
  }
}
.lock-icon{
  height: 16px;
  width: 16px;
  margin: 0 8px;
  cursor: pointer;
  color: #D7D7D7;
  &.is-locked{
    color: #FF5240;
  }
}
.lock-icon:hover{
  color: #817f7f;
}
.lock-icon.is-locked:hover{
  color: #f89e96;
}
</style>